package com.zbkj.service.service.mszs;

import cn.hutool.core.collection.CollUtil;
import com.github.pagehelper.PageHelper;
import com.zbkj.common.model.mszs.MszsHotel;
import com.zbkj.common.model.mszs.MszsRoomWifi;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.mszs.MszsRoomWifiRequest;
import com.zbkj.common.request.mszs.MszsRoomWifiSelectRequest;
import com.zbkj.common.response.mszs.MszsRoomWifiResponse;
import com.zbkj.service.dao.mszs.MszsHotelDao;
import com.zbkj.service.dao.mszs.MszsRoomWifiDao;
import com.zbkj.service.service.mszs.MszsRoomWifiService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @description 民宿助手-wifi信息
 * @author zhengkai.blog.csdn.net
 * @date 2023-11-16
 */
@Service
public class MszsRoomWifiServiceImpl implements MszsRoomWifiService {

    @Resource
    private MszsRoomWifiDao wifiMappper;
    @Resource
    private MszsHotelDao hotelDao;


    @Override
    public boolean insert(MszsRoomWifiRequest request) {
        MszsRoomWifi wifi=new MszsRoomWifi();
        BeanUtils.copyProperties(request, wifi);
        int tt = wifiMappper.insert(wifi);
        return tt > 0;
    }

    @Override
    public boolean update(MszsRoomWifiRequest request) {
        MszsRoomWifi wifi=new MszsRoomWifi();
        BeanUtils.copyProperties(request, wifi);
        int tt = wifiMappper.updateById(wifi);
        return tt > 0;
    }

    @Override
    public boolean delete(Integer id) {
        int tt = wifiMappper.deleteById(id);
        return tt > 0;
    }

    @Override
    public MszsRoomWifiResponse load(Integer id) {
        MszsRoomWifi wifi = wifiMappper.selectById(id);

        MszsRoomWifiResponse roomResponse=new MszsRoomWifiResponse();
        BeanUtils.copyProperties(wifi,roomResponse);

        MszsHotel hotel = hotelDao.selectById(wifi.getJdId());
        if (Objects.nonNull(hotel)){
            roomResponse.setJdName(hotel.getJdName());
        }
        return roomResponse;
    }

    @Override
    public List<MszsRoomWifiResponse> pageList(MszsRoomWifiSelectRequest request, PageParamRequest pageParamRequest) {

        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());

        List<MszsRoomWifiResponse> hotelList = wifiMappper.wifiList(request);
        if (CollUtil.isEmpty(hotelList)) {
            return CollUtil.newArrayList();
        }
        return hotelList;

    }
}
